Ext.onReady(function() {
	var toolbar = Ext.create('Ext.toolbar.Toolbar', {
		dock : 'top',
		items : [{
					text : '返回',
					xtype : 'button',
					listeners : {
						click : function() {
							location.href = "sysMgr/attach_type_mgr";
						}
					}
				}, {
					text : '保存',
					xtype : 'button',
					listeners : {
						click : function() {
							var form = Ext.getCmp("attach_type_form");
							if (!form.isValid()) {
								return;
							}
							Ext.Ajax.request({
								url : '/attach_type/update',
								params : {
									Id: attachmentType.Id,
									AttachmentGroupId: Ext.getCmp("attach_group").getValue(),
									Name : Ext.getCmp("attach_type_name").getValue(),
									Desp : Ext.getCmp("attach_type_desp").getValue()
								},
								callback : function(options, success, response) {
									if (success) {
										var result = Ext
												.decode(response.responseText);
										if (result.success) {
											location.href = "sysMgr/attach_type_mgr";
										}
										else{
											Ext.Msg.alert('错误', result.msg);
										}
									}
								}
							});
						}
					}
				}]
	});
	var attachGroupStore = Ext.create('Ext.data.Store', {
				fields : [{
							name : 'Id',
							type : 'int'
						}, 'Name'],
				proxy : {
					type : 'ajax',
					url : '/attach_group/all',
					reader : {
						type : 'json',
						root : 'data.rows'
					}
				},
				autoLoad : true
			});
	var attachGroup = Ext.create("Ext.form.ComboBox", {
				margin: '5 5',
				id : 'attach_group',
				editable : false,
				fieldLabel : '附件组',
				store : attachGroupStore,
				multiSelect : false,
				allowBlank : false,
				queryMode : 'local',
				displayField : 'Name',
				valueField : 'Id',
				value: Ext.isEmpty(attachmentType.AttachmentGroup)?'':attachmentType.AttachmentGroup.Id
			});

	var panel = Ext.create("Ext.form.Panel", {
				id : "attach_type_form",
				border : false,
				bodyBorder : false,
				dockedItems : [toolbar],
				items : [attachGroup, {
							xtype : 'container',
							layout : 'hbox',
							margin : '5 5',
							items : [{
										xtype : 'textfield',
										id : "attach_type_name",
										fieldLabel : '名称',
										value: attachmentType.Name,
										allowBlank : false
									}]
						}, {
							xtype : 'container',
							layout : 'hbox',
							margin : '5 5',
							items : [{
										xtype : 'textarea',
										width : 400,
										id : "attach_type_desp",
										value: attachmentType.Desp,
										fieldLabel : '描述'
									}]
						}]
			});
	Ext.create('Ext.Viewport', {
				layout : 'fit',
				style : 'background:none;background-color:white;',
				items : [panel]
			});
});